package br.com.intelsys.security.itoken;

import java.util.Date;

public class ITokenHiber implements IToken {

	private int codIToken;
	private ITokenType iTokenType;
	private int codOwner;
	private int codAux;
	private int uses;
	private int usesMax;
	private String token;
	private Status status;
	private Date dateExpires;
	private Date dateLastUse;

	public int getCodIToken() {
		return codIToken;
	}

	public void setCodIToken(int codIToken) {
		this.codIToken = codIToken;
	}

	public ITokenType getITokenType() {
		return iTokenType;
	}

	public void setITokenType(ITokenType iTokenType) {
		this.iTokenType = iTokenType;
	}

	public int getCodOwner() {
		return codOwner;
	}

	public void setCodOwner(int codOwner) {
		this.codOwner = codOwner;
	}

	public int getCodAux() {
		return codAux;
	}

	public void setCodAux(int codAux) {
		this.codAux = codAux;
	}

	public int getUses() {
		return uses;
	}

	public void setUses(int uses) {
		this.uses = uses;
	}

	public int getUsesMax() {
		return usesMax;
	}

	public void setUsesMax(int usesMax) {
		this.usesMax = usesMax;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getEncodedToken() {
		try {
			return (new TokenEncoder(getToken(), getCodAux()))
					.getEncodedToken();
		} catch (ITokenNotFoundException e) {
			return null;
		}
	}

	TokenEncoder getDecodedToken(String encodedToken)
			throws ITokenNotFoundException {
		return new TokenEncoder(encodedToken);
	}

	public Status getStatus() {
		return status;
	}

	public void setStatusStr(String status) {
		setStatus(Status.valueOf(status));
	}

	public String getStatusStr() {
		return getStatus() != null ? getStatus().toString() : null;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public ITokenType getiTokenType() {
		return iTokenType;
	}

	public void setiTokenType(ITokenType iTokenType) {
		this.iTokenType = iTokenType;
	}

	public Date getDateExpires() {
		return dateExpires;
	}

	public void setDateExpires(Date dateExpires) {
		this.dateExpires = dateExpires;
	}

	public String toString() {
		return "ITokenHiber [codIToken=" + codIToken + ", token=" + token + "]";
	}

	public Date getDateLastUse() {
		return dateLastUse;
	}

	public void setDateLastUse(Date dateLastUse) {
		this.dateLastUse = dateLastUse;
	}

}
